#ifndef __STREAMINGSOUND_OPENAL_H__
#define __STREAMINGSOUND_OPENAL_H__

#pragma once
#include "al/al.h"
#include "AbstractSound_OpenAL.h"

#define NUMBUFFERS 4

namespace openAL{

class StreamingBuffer_OpenAL;

class DLL_EXPORT StreamingSound_OpenAL :
	public AbstractSound_OpenAL
{
public:
	StreamingSound_OpenAL(StreamingBuffer_OpenAL* pStreamingBuffer);
	virtual ~StreamingSound_OpenAL(void);

	/**
	*	Start sound
	*/
	virtual bool play();

	/**
	*	Start ths sound by fading in.
	*	\param float fFadeTime
	*/
	virtual bool play_fadeIn(float fFadeTime);
	
	/**
	*	Stop sound
	*/
	virtual void stop();

	/**
	*	Fade out the sound and stop it afterwards.
	*	\param float fFadeOutTime
	*/
	virtual void fadeAndStop(float fFadeTime);

	/**
	 *	Raw implementation. Do nothing!
	 *	\todo Check if needed here too.
	 */
	virtual void setNumVoices(int _val) {}
	
	/*
	*	Get the state of the ISound:
	*	ISOUND_PLAYING, ISOUND_STOPPED...
	*/
	virtual int getState();

	/*
	*	Update loop. Should only be called, when sound is playing
	*	-at the moment called by the  audio-engine<
	*/
	virtual void update(const double &dt);

	
protected:
	/**
	*	Requests a source from the audio-engine
	*	fills the buffers with data an starts playing it
	*/
	bool initSourceAndPlay();						

	StreamingBuffer_OpenAL* m_pStreamingBuffer;		///< StreamingBuffer that holds the sounddata	
	ALuint m_aBuffers[NUMBUFFERS];					///< Array of Soundbuffers that are queued in loop (+1 Silence buffer between two sounds)

	bool m_bBufferHasMoreSamples;

	float m_fFadeFactor;							///< Between '1' and '0'. Used for fade in and fade out
	float m_fDeltaFade;								///< Gradient of the fade Used for fade in and fade out

};

}

#endif //__STREAMINGSOUND_OPENAL_H__